﻿#include "stdafx.h"
#include "LeiDian.h"


void  InitLeiDian()
{
	CString InstallDir;
	rw_reg::GetRegStr(_T("Software\\ChangZhi2\\dnplayer"), _T("InstallDir"), InstallDir, 260, HKEY_CURRENT_USER);
	if (!InstallDir.IsEmpty())
	{
		m_SimulatorPath.Format(_T("%sdnconsole.exe"), InstallDir);

		g_Dnplayer2Path = m_SimulatorPath.Left(m_SimulatorPath.GetLength() - 14);
		g_IniFile.SetString(_T("Set"), _T("模拟器路径"), m_SimulatorPath);
		g_IniFile.SetString(_T("Set"), _T("dnplayer路径"), g_Dnplayer2Path);
		DbgOut("[sdn] -------------g_Dnplayer2Path:%s", g_Dnplayer2Path);
	}
}


//获取模拟器路径
CString GetSimulatorPath()
{
	CString InstallDir;
	rw_reg::GetRegStr(_T("Software\\ChangZhi2\\dnplayer"), _T("InstallDir"), InstallDir, 260, HKEY_CURRENT_USER);
	if (!InstallDir.IsEmpty())
	{
		m_SimulatorPath.Format(_T("%sdnconsole.exe"), InstallDir);
		g_Dnplayer2Path = m_SimulatorPath.Left(m_SimulatorPath.GetLength() - 14);
		g_IniFile.SetString(_T("Set"), _T("模拟器路径"), m_SimulatorPath);
		g_IniFile.SetString(_T("Set"), _T("dnplayer路径"), g_Dnplayer2Path);
	}
	return m_SimulatorPath;
}


//打开模拟器
BOOL OpenSimulator(int index)
{
	CString strParam;
	strParam.Format(_T("%s launch --index %d"), m_SimulatorPath, index);
	TRACE("[sdn] strParam:%s", strParam);
	STARTUPINFO si = { sizeof(si) };
	PROCESS_INFORMATION pi;
	si.cb = sizeof(si);
	si.dwFlags = STARTF_USESHOWWINDOW;
	si.wShowWindow = SW_HIDE;

	return CreateProcess(NULL, strParam.GetBuffer(), NULL, NULL, FALSE, NULL,/*CREATE_SUSPENDED,*/NULL, NULL, &si, &pi);

}

//关闭单个模拟器
void CloseSingleSimulator(int index)
{
	CString strParam;
	strParam.Format(_T("%s quit --index %d"), m_SimulatorPath, index);
	STARTUPINFO si = { sizeof(si) };
	PROCESS_INFORMATION pi;
	si.cb = sizeof(si);
	si.dwFlags = STARTF_USESHOWWINDOW;
	si.wShowWindow = SW_HIDE;

	CreateProcess(NULL, strParam.GetBuffer(), NULL, NULL, FALSE, NULL,/*CREATE_SUSPENDED,*/NULL, NULL, &si, &pi);
}

//关闭单个应用
void CloseSingleApp(int index)
{
	CString strParam;
	//strParam.Format(_T("%s killapp --index %d --packagename com.tencent.tmgp.tstl"), m_SimulatorPath, index);
	//strParam.Format(_T("%s killapp --index %d --packagename com.tencent.tmgp.tstl"), m_SimulatorPath, index);
	strParam.Format(_T("%s killapp --index %d --packagename com.pwrd.wlwz.laohu"), m_SimulatorPath, index);
	STARTUPINFO si = { sizeof(si) };
	PROCESS_INFORMATION pi;
	si.cb = sizeof(si);
	si.dwFlags = STARTF_USESHOWWINDOW;
	si.wShowWindow = SW_HIDE;

	CreateProcess(NULL, strParam.GetBuffer(), NULL, NULL, FALSE, NULL,/*CREATE_SUSPENDED,*/NULL, NULL, &si, &pi);
}


//关闭所有模拟器
void CloseAllSimulator()
{
	CString strParam;
	strParam.Format("%s quitall", m_SimulatorPath);
	STARTUPINFO si = { sizeof(si) };
	PROCESS_INFORMATION pi;
	si.cb = sizeof(si);
	si.dwFlags = STARTF_USESHOWWINDOW;
	si.wShowWindow = SW_HIDE;

	CreateProcess(NULL, strParam.GetBuffer(), NULL, NULL, FALSE, NULL,/*CREATE_SUSPENDED,*/NULL, NULL, &si, &pi);
}



//重启单个模拟器
void RebootSingleSimulator(int index)
{
	CString strParam;
	strParam.Format(_T("%s reboot --index %d"), m_SimulatorPath, index);
	STARTUPINFO si = { sizeof(si) };
	PROCESS_INFORMATION pi;
	si.cb = sizeof(si);
	si.dwFlags = STARTF_USESHOWWINDOW;
	si.wShowWindow = SW_HIDE;

	CreateProcess(NULL, strParam.GetBuffer(), NULL, NULL, FALSE, NULL,/*CREATE_SUSPENDED,*/NULL, NULL, &si, &pi);

}


//清理应用信息
void ClearSingleAppInfo(int index)
{
	//adb shell pm clear packageName
	CString strParam;
	//strParam.Format(_T("%s adb --index %d --command \"shell pm clear com.pwrd.wlwz.laohu\""), m_SimulatorPath, index);
	strParam.Format(_T("%s adb --index %d --command \"shell pm clear com.pwrd.wlwz.laohu\""), m_SimulatorPath, index);
	STARTUPINFO si = { sizeof(si) };
	PROCESS_INFORMATION pi;
	si.cb = sizeof(si);
	si.dwFlags = STARTF_USESHOWWINDOW;
	si.wShowWindow = SW_HIDE;

	CreateProcess(NULL, strParam.GetBuffer(), NULL, NULL, FALSE, NULL,/*CREATE_SUSPENDED,*/NULL, NULL, &si, &pi);

}

void DownCpu(int index, int iRate)
{
	//downcpu --index 0 --rate 50
	CString strParam;
	strParam.Format(_T("%s downcpu --index %d --rate %d"), m_SimulatorPath, index, iRate);
	//strParam.Format(_T("%s killapp --index %d --packagename com.tencent.tmgp.tstlty"), m_SimulatorPath, index);
	STARTUPINFO si = { sizeof(si) };
	PROCESS_INFORMATION pi;
	si.cb = sizeof(si);
	si.dwFlags = STARTF_USESHOWWINDOW;
	si.wShowWindow = SW_HIDE;

	CreateProcess(NULL, strParam.GetBuffer(), NULL, NULL, FALSE, NULL,/*CREATE_SUSPENDED,*/NULL, NULL, &si, &pi);
}

//关闭浏览器
void CloseBrowser(int iIndex)
{
	//#define EXECDOSCMD "J:\\ChangZhi2\\dnplayer2\\dnconsole.exe adb --index 0 --command \"shell killall com.android.browser\"" //可以换成你的命令
	CString strParam;
	//strParam.Format(_T("%s adb --index %d --command \"shell pm clear com.pwrd.wlwz.laohu\""), m_SimulatorPath, index);
	strParam.Format(_T("%s adb --index %d --command \"shell killall com.android.browser\""), m_SimulatorPath, iIndex);
	STARTUPINFO si = { sizeof(si) };
	PROCESS_INFORMATION pi;
	si.cb = sizeof(si);
	si.dwFlags = STARTF_USESHOWWINDOW;
	si.wShowWindow = SW_HIDE;

	CreateProcess(NULL, strParam.GetBuffer(), NULL, NULL, FALSE, NULL,/*CREATE_SUSPENDED,*/NULL, NULL, &si, &pi);
}
//dn_获取进程ID
void Dn_GetProcessID(int iIndex)
{
	CString strParam;
	strParam.Format(_T("%s adb --index %d --command \"shell ps\""), m_SimulatorPath, iIndex);
	DbgOut("[sdn] strParam:%s", strParam);
	CString strResult1, strResult2, errInfo;
	CallCMD(strParam, strResult1, errInfo);
	GetCmdResult(strParam.GetBuffer(), strResult2);
}

//adb shell input text 字符串(不支持中文)
void InputStr(int index, CString str)
{
	//	5554 = 0
	//	5556 = 1


	CString strIP;
	strIP.Format("-s emulator-%d", 5554 + index * 2);

	CString strParam;
	//strParam.Format(_T("%s adb %s shell input text %s"), m_SimulatorPath, strIP, str);
	strParam.Format(_T("%s adb --index %d --command \"shell input text %s\""), m_SimulatorPath, index, str);
	STARTUPINFO si = { sizeof(si) };
	PROCESS_INFORMATION pi;
	si.cb = sizeof(si);
	si.dwFlags = STARTF_USESHOWWINDOW;
	si.wShowWindow = SW_HIDE;

	CreateProcess(NULL, strParam.GetBuffer(), NULL, NULL, FALSE, NULL,/*CREATE_SUSPENDED,*/NULL, NULL, &si, &pi);

}


//关闭所有模拟器
void LDList2()
{
	CString strParam;
	strParam.Format(_T("%s list2"), m_SimulatorPath);
	STARTUPINFO si = { sizeof(si) };
	PROCESS_INFORMATION pi;
	si.cb = sizeof(si);
	si.dwFlags = STARTF_USESHOWWINDOW;
	si.wShowWindow = SW_HIDE;

	CreateProcess(NULL, strParam.GetBuffer(), NULL, NULL, FALSE, NULL,/*CREATE_SUSPENDED,*/NULL, NULL, &si, &pi);
}

bool CallCMD(CString cmd, CString &outPut, CString& errInfo)
{
	outPut = L"";
	SECURITY_ATTRIBUTES sa;
	HANDLE hRead, hWrite;
	sa.nLength = sizeof(SECURITY_ATTRIBUTES);
	sa.lpSecurityDescriptor = NULL; //使用系统默认的安全描述符  
	sa.bInheritHandle = TRUE; //创建的进程继承句柄  
	if (!CreatePipe(&hRead, &hWrite, &sa, 0)) //创建匿名管道  
	{
		errInfo.Format(L"创建管道失败，错误码:%d", GetLastError());
		//TRACE("创建管道失败，错误码:%d\n", GetLastError());
		DbgOut(L"[sdn] %s", errInfo);
		return false;
	}

	STARTUPINFO si;
	PROCESS_INFORMATION pi;

	ZeroMemory(&si, sizeof(STARTUPINFO));

	si.cb = sizeof(STARTUPINFO);
	GetStartupInfo(&si);
	si.hStdError = hWrite;
	si.hStdOutput = hWrite; //新创建进程的标准输出连在写管道一端  
	si.wShowWindow = SW_HIDE; //隐藏窗口  
	si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;

	TCHAR cmd2[1024];
	_tcscpy_s(cmd2, cmd);
	if (!CreateProcess(NULL, cmd2, NULL, NULL, TRUE, NULL, NULL, NULL, &si, &pi)) //创建子进程  
	{
		errInfo.Format(L"创建CreateProcess失败，错误码:%d", GetLastError());
		//errInfo = "创建CreateProcess失败，错误码:" + GetLastError();
		DbgOut(L"[sdn] %s", errInfo);
		return false;
	}
	CloseHandle(hWrite); //关闭管道句柄  

	char buffer[81920] = { 0 };
	DWORD bytesRead;

	while (true)
	{
		if (ReadFile(hRead, buffer, 1, &bytesRead, NULL) == NULL) //读取管道  
			break;
		outPut += buffer;
		//Sleep(100);
	}
	CloseHandle(hRead);
	return true;
}
//执行CMD命令返回命令结果
BOOL GetCmdResult(const char * szDosCmd, CString &sRetVal)
{
	CString errInfo;
	//创建管道
	SECURITY_ATTRIBUTES sa;
	HANDLE hRead, hWrite;
	sa.nLength = sizeof(SECURITY_ATTRIBUTES);
	sa.lpSecurityDescriptor = NULL;
	sa.bInheritHandle = TRUE;
	if (!CreatePipe(&hRead, &hWrite, &sa, 0))
	{
		errInfo.Format(L"创建CreateProcess失败，错误码:%d", GetLastError());
		//errInfo = "创建CreateProcess失败，错误码:" + GetLastError();
		DbgOut(L"[sdn] %s", errInfo);
		return FALSE;
	}

	//组装命令行,长达1K的命令行,应该够用
	char command[1024];
	strcpy(command, L"Cmd.exe /C ");
	strcat(command, szDosCmd);

	//返回进程在启动时被指定的STARTUPINFO结构
	STARTUPINFO si;
	PROCESS_INFORMATION pi;
	si.cb = sizeof(STARTUPINFO);
	GetStartupInfo(&si);
	si.hStdError = hWrite;            //把创建进程的标准错误重定向到管道输入  
	si.hStdOutput = hWrite;           //把创建进程的标准输出重定向到管道输入  
	si.wShowWindow = SW_HIDE;
	si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;

	//执行命名,创建子进程 
	//第五个参数bInHeritHandles也是一定要设置为TRUE,因为既然要让新进程能输出信息到调用他的进程里,就必须让新的进程继承调用进程的句柄.
	if (!CreateProcess(NULL, command, NULL, NULL, TRUE, NULL, NULL, NULL, &si, &pi))
	{
		errInfo.Format(L"创建CreateProcess失败，错误码:%d", GetLastError());
		//errInfo = "创建CreateProcess失败，错误码:" + GetLastError();
		DbgOut(L"[sdn] %s", errInfo);
		CloseHandle(hWrite);
		CloseHandle(hRead);
		return FALSE;
	}

	//关闭管道输入
	CloseHandle(hWrite);

	//读取管道输出
	DWORD dwRead = 0;
	DWORD dwBlock = 4096;
	char szBuffer[4096 + 1] = { 0 };
	char buffer[4096] = { 0 };
	DWORD bytesRead;
	while (ReadFile(hRead, buffer, 4095, &bytesRead, NULL))
	{
		DbgOut(L"[sdn] szBuffer:%s", buffer);

		sRetVal += buffer;
	}

	//关闭管道输出
	CloseHandle(hRead);
	return TRUE;
}


//清理缓存
void ClearCach(int iIndex)
{
	CString strParam;
	strParam.Format(L"%s\\ld.exe -s %d pm clear com.netease.wyclx", g_Dnplayer2Path, iIndex);
	STARTUPINFO si = { sizeof(si) };
	PROCESS_INFORMATION pi;
	si.cb = sizeof(si);
	si.dwFlags = STARTF_USESHOWWINDOW;
	si.wShowWindow = SW_HIDE;

	CreateProcess(NULL, strParam.GetBuffer(), NULL, NULL, FALSE, NULL,/*CREATE_SUSPENDED,*/NULL, NULL, &si, &pi);
}

//取APK路径
CString GetApkPath(int iIndex)
{
	CString strParam;
	strParam.Format(L"%s\\ld.exe -s %d pm path com.pwrd.wlwz.laohu", g_Dnplayer2Path, iIndex);

	CString strResult;
	GetCmdResult(strParam.GetBuffer(), strResult);
	return strResult;
}

//取dns
CString GetDns(int iIndex)
{
	CString strParam1;
	strParam1.Format(L"%s\\ld.exe -s %d getprop dhcp.eth0.dns1", g_Dnplayer2Path, iIndex);

	CString strParam2;
	strParam2.Format(L"%s\\ld.exe -s %d getprop dhcp.eth0.dns2", g_Dnplayer2Path, iIndex);


	CString strResult1, strResult2, strResult;
	GetCmdResult(strParam1.GetBuffer(), strResult1);
	GetCmdResult(strParam2.GetBuffer(), strResult2);
	strResult = strResult1 + "," + strResult2;
	return strResult;
}

//取imei
CString GetIMEI(int iIndex)
{
	CString strParam;
	strParam.Format(L"%s\\ld.exe -s %d getprop phone.imei", g_Dnplayer2Path, iIndex);

	CString strResult;
	GetCmdResult(strParam.GetBuffer(), strResult);
	return strResult;
}

//取imsi
CString GetIMSI(int iIndex)
{
	CString strParam;
	strParam.Format(L"%s\\ld.exe -s %d getprop phone.imsi", g_Dnplayer2Path, iIndex);

	CString strResult;
	GetCmdResult(strParam.GetBuffer(), strResult);
	return strResult;
}


//取IP
CString GetIP(int iIndex)
{
	CString strParam;
	strParam.Format(L"%s\\ld.exe -s %d getprop phone.imsi", g_Dnplayer2Path, iIndex);

	CString strResult;
	GetCmdResult(strParam.GetBuffer(), strResult);
	return strResult;
}
//取Mac
CString GetMac(int iIndex)
{
	CString strParam;
	strParam.Format(L"%s\\ld.exe -s %d cat /sys/class/net/eth0/address", g_Dnplayer2Path, iIndex);

	CString strResult;
	GetCmdResult(strParam.GetBuffer(), strResult);
	return strResult;
}

//取SIM序号
CString GetSIM(int iIndex)
{
	CString strParam;
	strParam.Format("%s\\ld.exe -s %d getprop phone.simserial", g_Dnplayer2Path, iIndex);

	CString strResult;
	GetCmdResult(strParam.GetBuffer(), strResult);
	return strResult;
}

//取安卓ID
CString GetAndriodID(int iIndex)
{
	CString strParam;
	strParam.Format("%s\\ld.exe -s %d getprop phone.androidid", g_Dnplayer2Path, iIndex);

	CString strResult;
	GetCmdResult(strParam.GetBuffer(), strResult);
	return strResult;
}
//取安卓版本
CString GetAndriodVersion(int iIndex)
{
	CString strParam;
	strParam.Format("%s\\ld.exe -s %d getprop ro.build.version.release", g_Dnplayer2Path, iIndex);

	CString strResult;
	GetCmdResult(strParam.GetBuffer(), strResult);
	return strResult;
}
//取进程ID
CString GetProcessID(int iIndex)
{
	CString strParam;
	strParam.Format("%s\\ld.exe -s %d pm list packages", g_Dnplayer2Path, iIndex);

	CString strResult, strErr;

	USES_CONVERSION;
	char* col = T2A(strParam.GetBuffer(0));

	GetCmdResult(col, strResult);

	DbgOut("[sdn] strParam:%s", strParam);
	DbgOut("[sdn] GetProcessID:%s", strResult);
	return strResult;
}
//取进程列表
CString GetProcessList(int iIndex)
{
	CString strParam;
	strParam.Format("%s\\ld.exe -s %d ps", g_Dnplayer2Path, iIndex);

	CString strResult, strErr;
	CallCMD(strParam.GetBuffer(), strResult, strErr);
	DbgOut("[sdn] GetProcessList:%s", strResult);
	return strResult;
}
//取手机厂商
CString GetPhoneFirm(int iIndex)
{
	CString strParam;
	strParam.Format("%s\\ld.exe -s %d getprop ro.product.manufacturer", g_Dnplayer2Path, iIndex);

	CString strResult;
	GetCmdResult(strParam.GetBuffer(), strResult);
	return strResult;
}
//取手机号码
CString GetPhoneNumber(int iIndex)
{
	CString strParam;
	strParam.Format("%s\\ld.exe -s %d getprop phone.number", g_Dnplayer2Path, iIndex);

	CString strResult;
	GetCmdResult(strParam.GetBuffer(), strResult);
	return strResult;
}
//取手机型号
CString GetPhoneModel(int iIndex)
{
	CString strParam;
	strParam.Format("%s\\ld.exe -s %d getprop ro.product.model", g_Dnplayer2Path, iIndex);

	CString strResult;
	GetCmdResult(strParam.GetBuffer(), strResult);
	return strResult;
}
//取网关
CString GetGateWay(int iIndex)
{
	CString strParam;
	strParam.Format("%s\\ld.exe -s %d getprop dhcp.eth0.gateway", g_Dnplayer2Path, iIndex);

	CString strResult;
	GetCmdResult(strParam.GetBuffer(), strResult);
	return strResult;
}
//删除文件
void LDDeleteFile(int iIndex, CString strFilePath)
{
	CString strParam;
	strParam.Format("%s\\ld.exe -s %d rm %s", g_Dnplayer2Path, iIndex, strFilePath);
	STARTUPINFO si = { sizeof(si) };
	PROCESS_INFORMATION pi;
	si.cb = sizeof(si);
	si.dwFlags = STARTF_USESHOWWINDOW;
	si.wShowWindow = SW_HIDE;

	CreateProcess(NULL, strParam.GetBuffer(), NULL, NULL, FALSE, NULL,/*CREATE_SUSPENDED,*/NULL, NULL, &si, &pi);
}
//删除文件夹
void LDDeleteFolder(int iIndex, CString strFolderPath)
{
	CString strParam;
	strParam.Format("%s\\ld.exe -s %d rm -r %s", g_Dnplayer2Path, iIndex, strFolderPath);
	STARTUPINFO si = { sizeof(si) };
	PROCESS_INFORMATION pi;
	si.cb = sizeof(si);
	si.dwFlags = STARTF_USESHOWWINDOW;
	si.wShowWindow = SW_HIDE;

	CreateProcess(NULL, strParam.GetBuffer(), NULL, NULL, FALSE, NULL,/*CREATE_SUSPENDED,*/NULL, NULL, &si, &pi);
}
//置dns
void SetDns(int iIndex, CString strDns1, CString strDns2)
{
	CString strParam1, strParam2;
	strParam1.Format("%s\\ld.exe -s %d setprop dhcp.eth0.dns1 %s", g_Dnplayer2Path, iIndex, strDns1);

	strParam2.Format("%s\\ld.exe -s %d setprop dhcp.eth0.dns2 %s", g_Dnplayer2Path, iIndex, strDns2);

	STARTUPINFO si = { sizeof(si) };
	PROCESS_INFORMATION pi;
	si.cb = sizeof(si);
	si.dwFlags = STARTF_USESHOWWINDOW;
	si.wShowWindow = SW_HIDE;

	CreateProcess(NULL, strParam1.GetBuffer(), NULL, NULL, FALSE, NULL,/*CREATE_SUSPENDED,*/NULL, NULL, &si, &pi);
	CreateProcess(NULL, strParam2.GetBuffer(), NULL, NULL, FALSE, NULL,/*CREATE_SUSPENDED,*/NULL, NULL, &si, &pi);
}
//置IMEI
void SetIMEI(int iIndex, CString strIMEI)
{
	CString strParam;
	strParam.Format("%s\\ld.exe -s %d setprop phone.imei %s", g_Dnplayer2Path, iIndex, strIMEI);
	STARTUPINFO si = { sizeof(si) };
	PROCESS_INFORMATION pi;
	si.cb = sizeof(si);
	si.dwFlags = STARTF_USESHOWWINDOW;
	si.wShowWindow = SW_HIDE;

	CreateProcess(NULL, strParam.GetBuffer(), NULL, NULL, FALSE, NULL,/*CREATE_SUSPENDED,*/NULL, NULL, &si, &pi);
}
//置IMSI
void SetIMSI(int iIndex, CString strIMSI)
{
	CString strParam;
	strParam.Format("%s\\ld.exe -s %d setprop phone.imsi %s", g_Dnplayer2Path, iIndex, strIMSI);
	STARTUPINFO si = { sizeof(si) };
	PROCESS_INFORMATION pi;
	si.cb = sizeof(si);
	si.dwFlags = STARTF_USESHOWWINDOW;
	si.wShowWindow = SW_HIDE;

	CreateProcess(NULL, strParam.GetBuffer(), NULL, NULL, FALSE, NULL,/*CREATE_SUSPENDED,*/NULL, NULL, &si, &pi);
}
//置IP
void SetIP(int iIndex, CString strIP)
{
	CString strParam;
	strParam.Format("%s\\ld.exe -s %d ifconfig eth0 %s netmask 255.255.255.0", g_Dnplayer2Path, iIndex, strIP);
	STARTUPINFO si = { sizeof(si) };
	PROCESS_INFORMATION pi;
	si.cb = sizeof(si);
	si.dwFlags = STARTF_USESHOWWINDOW;
	si.wShowWindow = SW_HIDE;

	CreateProcess(NULL, strParam.GetBuffer(), NULL, NULL, FALSE, NULL,/*CREATE_SUSPENDED,*/NULL, NULL, &si, &pi);

}
//置Mac
void SetMac(int iIndex, CString strMac)
{
	CString strParam;
	strParam.Format("%s\\ld.exe -s %d setprop dhcp.eth0.mac %s", g_Dnplayer2Path, iIndex, strMac);
	STARTUPINFO si = { sizeof(si) };
	PROCESS_INFORMATION pi;
	si.cb = sizeof(si);
	si.dwFlags = STARTF_USESHOWWINDOW;
	si.wShowWindow = SW_HIDE;

	CreateProcess(NULL, strParam.GetBuffer(), NULL, NULL, FALSE, NULL,/*CREATE_SUSPENDED,*/NULL, NULL, &si, &pi);
}

//置SIM
void SetSIM(int iIndex, CString strSIM)
{
	CString strParam;
	strParam.Format("%s\\ld.exe -s %d setprop phone.simserial %s", g_Dnplayer2Path, iIndex, strSIM);
	STARTUPINFO si = { sizeof(si) };
	PROCESS_INFORMATION pi;
	si.cb = sizeof(si);
	si.dwFlags = STARTF_USESHOWWINDOW;
	si.wShowWindow = SW_HIDE;

	CreateProcess(NULL, strParam.GetBuffer(), NULL, NULL, FALSE, NULL,/*CREATE_SUSPENDED,*/NULL, NULL, &si, &pi);
}

//置安卓ID
void SetAndroidID(int iIndex, CString strID)
{
	CString strParam;
	strParam.Format("%s\\ld.exe -s %d setprop phone.androidid  %s", g_Dnplayer2Path, iIndex, strID);
	STARTUPINFO si = { sizeof(si) };
	PROCESS_INFORMATION pi;
	si.cb = sizeof(si);
	si.dwFlags = STARTF_USESHOWWINDOW;
	si.wShowWindow = SW_HIDE;

	CreateProcess(NULL, strParam.GetBuffer(), NULL, NULL, FALSE, NULL,/*CREATE_SUSPENDED,*/NULL, NULL, &si, &pi);
}
//置手机厂商
void SetPhoneFirm(int iIndex, CString strFirm)
{
	CString strParam;
	strParam.Format(L"%s\\ld.exe -s %d setprop phone.manufacturer #%s#", g_Dnplayer2Path, iIndex, strFirm);
	STARTUPINFO si = { sizeof(si) };
	PROCESS_INFORMATION pi;
	si.cb = sizeof(si);
	si.dwFlags = STARTF_USESHOWWINDOW;
	si.wShowWindow = SW_HIDE;

	CreateProcess(NULL, strParam.GetBuffer(), NULL, NULL, FALSE, NULL,/*CREATE_SUSPENDED,*/NULL, NULL, &si, &pi);
}
//置手机号码
void SetPhoneNumber(int iIndex, CString strPhoneNumber)
{
	CString strParam;
	strParam.Format("%s\\ld.exe -s %d setprop phone.linenum %s", g_Dnplayer2Path, iIndex, strPhoneNumber);
	STARTUPINFO si = { sizeof(si) };
	PROCESS_INFORMATION pi;
	si.cb = sizeof(si);
	si.dwFlags = STARTF_USESHOWWINDOW;
	si.wShowWindow = SW_HIDE;

	CreateProcess(NULL, strParam.GetBuffer(), NULL, NULL, FALSE, NULL,/*CREATE_SUSPENDED,*/NULL, NULL, &si, &pi);
}
//置手机型号
void SetPhoneModel(int iIndex, CString strPhoneModel)
{
	CString strParam;
	strParam.Format(L"%s\\ld.exe -s %d setprop phone.model #%s#", g_Dnplayer2Path, iIndex, strPhoneModel);
	STARTUPINFO si = { sizeof(si) };
	PROCESS_INFORMATION pi;
	si.cb = sizeof(si);
	si.dwFlags = STARTF_USESHOWWINDOW;
	si.wShowWindow = SW_HIDE;

	CreateProcess(NULL, strParam.GetBuffer(), NULL, NULL, FALSE, NULL,/*CREATE_SUSPENDED,*/NULL, NULL, &si, &pi);
}
//置网关
void SetGateWay(int iIndex, CString strDns1, CString strDns2)
{
	CString strParam1, strParam2;
	strParam1.Format(L"%s\\ld.exe -s %d setprop dhcp.eth0.dns1 %s", g_Dnplayer2Path, iIndex, strDns1);
	strParam2.Format(L"%s\\ld.exe -s %d setprop dhcp.eth0.dns2 %s", g_Dnplayer2Path, iIndex, strDns2);
	STARTUPINFO si = { sizeof(si) };
	PROCESS_INFORMATION pi;
	si.cb = sizeof(si);
	si.dwFlags = STARTF_USESHOWWINDOW;
	si.wShowWindow = SW_HIDE;

	CreateProcess(NULL, strParam1.GetBuffer(), NULL, NULL, FALSE, NULL,/*CREATE_SUSPENDED,*/NULL, NULL, &si, &pi);
	CreateProcess(NULL, strParam2.GetBuffer(), NULL, NULL, FALSE, NULL,/*CREATE_SUSPENDED,*/NULL, NULL, &si, &pi);
}

//终止进程
void StopProcess(int iIndex, CString strProcessID)
{
	CString strParam;
	strParam.Format(L"%s\\ld.exe -s %d kill %s", g_Dnplayer2Path, iIndex, strProcessID);
	STARTUPINFO si = { sizeof(si) };
	PROCESS_INFORMATION pi;
	si.cb = sizeof(si);
	si.dwFlags = STARTF_USESHOWWINDOW;
	si.wShowWindow = SW_HIDE;

	CreateProcess(NULL, strParam.GetBuffer(), NULL, NULL, FALSE, NULL,/*CREATE_SUSPENDED,*/NULL, NULL, &si, &pi);
}

// 随机生成手机号码
CString GetRandomTel()
{

	return L"";
}


BOOL __CallCMD(CString cmd)
{
	CString outPut, errInfo;
	outPut = L"";
	SECURITY_ATTRIBUTES sa;
	HANDLE hRead, hWrite;
	sa.nLength = sizeof(SECURITY_ATTRIBUTES);
	sa.lpSecurityDescriptor = NULL; //使用系统默认的安全描述符  
	sa.bInheritHandle = TRUE; //创建的进程继承句柄  
	if (!CreatePipe(&hRead, &hWrite, &sa, 0)) //创建匿名管道  
	{
		errInfo.Format(L"创建管道失败，错误码:%d", GetLastError());
		//TRACE("创建管道失败，错误码:%d\n", GetLastError());
		return FALSE;
	}

	STARTUPINFO si;
	PROCESS_INFORMATION pi;

	ZeroMemory(&si, sizeof(STARTUPINFO));

	si.cb = sizeof(STARTUPINFO);
	GetStartupInfo(&si);
	si.hStdError = hWrite;
	si.hStdOutput = hWrite; //新创建进程的标准输出连在写管道一端  
	si.wShowWindow = SW_HIDE; //隐藏窗口  
	si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;

	TCHAR cmd2[1024];
	_tcscpy_s(cmd2, cmd);
	if (!CreateProcess(NULL, cmd2, NULL, NULL, TRUE, NULL, NULL, NULL, &si, &pi)) //创建子进程  
	{
		errInfo.Format(L"创建CreateProcess失败，错误码:%d", GetLastError());
		//errInfo = "创建CreateProcess失败，错误码:" + GetLastError();
		return FALSE;
	}
	CloseHandle(hWrite); //关闭管道句柄  

	char buffer[81920] = { 0 };
	DWORD bytesRead;

	while (true)
	{
		if (ReadFile(hRead, buffer, 1, &bytesRead, NULL) == NULL) //读取管道  
			break;
		outPut += buffer;
		Sleep(100);
	}
	CloseHandle(hRead);
	return TRUE;
}


